package com.turnengine.client.local.location.bean;

import com.turnengine.client.local.location.enums.LocationSignup;
import com.turnengine.client.local.unit.bean.IUnitCount;
import java.util.List;
import org.apache.commons.lang.builder.CompareToBuilder;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

/**
 * The Generated Location.
 */
public class GeneratedLocation implements IGeneratedLocation, Comparable<IGeneratedLocation> {

	/** The signup. */
	private LocationSignup signup = LocationSignup.SIGNUP;
	/** The signup faction id. */
	private int signupFactionId = -1;
	/** The unit list. */
	private List<IUnitCount> unitList;

	/**
	 * Creates a new Generated Location.
	 */
	public GeneratedLocation() {
	}

	/**
	 * Creates a new Generated Location.
	 * @param signup the signup
	 * @param signupFactionId the signup faction id
	 * @param unitList the unit list
	 */
	public GeneratedLocation(LocationSignup signup, int signupFactionId, List<IUnitCount> unitList) {
		setSignup(signup);
		setSignupFactionId(signupFactionId);
		setUnitList(unitList);
	}

	/**
	 * Creates a new Generated Location.
	 * @param generatedLocation the generated location
	 */
	public GeneratedLocation(GeneratedLocation generatedLocation) {
		setSignup(generatedLocation.getSignup());
		setSignupFactionId(generatedLocation.getSignupFactionId());
		setUnitList(generatedLocation.getUnitList());
	}

	/**
	 * Creates a new Generated Location.
	 * @param iGeneratedLocation the i generated location
	 */
	public GeneratedLocation(IGeneratedLocation iGeneratedLocation) {
		setSignup(iGeneratedLocation.getSignup());
		setSignupFactionId(iGeneratedLocation.getSignupFactionId());
		setUnitList(iGeneratedLocation.getUnitList());
	}

	/**
	 * Returns the signup.
	 * @return the signup.
	 */
	public LocationSignup getSignup() {
		return signup;
	}

	/**
	 * Returns the signup faction id.
	 * @return the signup faction id.
	 */
	public int getSignupFactionId() {
		return signupFactionId;
	}

	/**
	 * Returns the unit list.
	 * @return the unit list.
	 */
	public List<IUnitCount> getUnitList() {
		return unitList;
	}

	/**
	 * Sets the signup.
	 * @param signup the signup to set.
	 */
	public void setSignup(LocationSignup signup) {
		this.signup = signup;
	}

	/**
	 * Sets the signup faction id.
	 * @param signupFactionId the signup faction id to set.
	 */
	public void setSignupFactionId(int signupFactionId) {
		this.signupFactionId = signupFactionId;
	}

	/**
	 * Sets the unit list.
	 * @param unitList the unit list to set.
	 */
	public void setUnitList(List<IUnitCount> unitList) {
		this.unitList = unitList;
	}

	/**
	 * Returns the hash code.
	 * @return the hash code.
	 */
	@Override
	public int hashCode() {
		HashCodeBuilder hash = new HashCodeBuilder(701, 37);
		hash.append(signup);
		hash.append(signupFactionId);
		hash.append(unitList);
		return hash.toHashCode();
	}

	/**
	 * Returns true if this is equal to the given object.
	 * @param object the object to compare.
	 * @return true if this is equal to the given object.
	 */
	@Override
	public boolean equals(Object object) {
		if (object == this) {
			return true;
		}
		if (object instanceof GeneratedLocation) {
			GeneratedLocation compare = (GeneratedLocation) object;
			EqualsBuilder equals = new EqualsBuilder();
			equals.append(this.signup, compare.signup);
			equals.append(this.signupFactionId, compare.signupFactionId);
			equals.append(this.unitList, compare.unitList);
			return equals.isEquals();
		}
		return false;
	}

	/**
	 * Compare this to the given object.
	 * @param compare the object to compare to.
	 * @return the result of the comparison.
	 */
	@Override
	public int compareTo(IGeneratedLocation compare) {
		CompareToBuilder builder = new CompareToBuilder();
		builder.append(this.signup, compare.getSignup());
		builder.append(this.signupFactionId, compare.getSignupFactionId());
		builder.append(this.unitList, compare.getUnitList());
		return builder.toComparison();
	}

	/**
	 * Returns this as a string.
	 * @return this as a string.
	 */
	@Override
	public String toString() {
		ToStringBuilder string = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE);
		if (signup != null) {
			string.append("signup", signup);
		}
		string.append("signupFactionId", signupFactionId);
		if (unitList != null) {
			string.append("unitList", unitList);
		}
		return string.toString();
	}
}
